import { getDetails } from "@/api/service/store/store";

interface PageForm {
  title: string;
  logo: string;
  theme: "light" | "dark" | undefined;
  stock: number;
  imageUrl?: string;
  videoUrl?: string;
}
export const storeConfig = ref<PageForm>({
  title: "",
  logo: "",
  theme: "dark",
  stock: 0
});
export const themeOptions = [
  {
    label: "黑暗",
    value: "dark"
  },
  {
    label: "亮色",
    value: "light"
  }
];

export const getStoreConfig = async () => {
  let result = await getDetails();

  if (!result?.data) return;
  console.log();
  try {
    if (typeof result.data === "string") {
      result.data = JSON.stringify(result.data);
    }
    const { logo, title, theme, stock, imageUrl, videoUrl } = result.data;

    storeConfig.value.logo = logo;
    storeConfig.value.stock = stock || 0;
    storeConfig.value.theme = theme || "dark";

    storeConfig.value.title = title ?? "ESL";
    storeConfig.value.imageUrl = imageUrl;
    storeConfig.value.videoUrl = videoUrl;
    document.title = title || "ESL";
  } catch (error) {}
};
